package com.example.parking.config;


import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import okhttp3.*;

import java.io.IOException;

/**
 * 获取鉴定权限Token
 */
public class Sample {
    static final OkHttpClient HTTP_CLIENT = new OkHttpClient().newBuilder().build();

    public static JSONObject getAccessToken() throws IOException {
        MediaType mediaType = MediaType.parse("application/json");
        RequestBody body = RequestBody.create(mediaType, "");
        Request request = new Request.Builder()
                .url("https://aip.baidubce.com/oauth/2.0/token?client_id=a95eiedvaQlHtuGtYkB08sIj" +
                        "&client_secret=Ff7GR1ZM1AdGAq3LdZYiCalEO7Dgjuiw" +
                        "&grant_type=client_credentials")
                .method("POST", body)
                .addHeader("Content-Type", "application/json")
                .addHeader("Accept", "application/json")
                .build();
        Response response = HTTP_CLIENT.newCall(request).execute();
        JSONObject jsonObject = JSONUtil.parseObj(response.body().string());
        return jsonObject;
    }

}
